﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Browser;
using System.Reflection;
using ASPItalia.ModelVirtualCasting.Web.RiaServices;

namespace ASPItalia.ModelVirtualCasting.Silverlight.BackOffice.Manager
{
  public static class Helper
  {
    /// <summary>
    /// Restituisce il path del sito host
    /// </summary>
    /// <returns></returns>
    public static string GetBaseUri()
    {
      return "http://localhost:39956/";

      string absoluteUriString = HtmlPage.Document.DocumentUri.AbsoluteUri;

      string localPath = HtmlPage.Document.DocumentUri.LocalPath.Replace("/", "");
      string path = absoluteUriString.Replace(localPath, "");
      if (!String.IsNullOrEmpty(HtmlPage.Document.DocumentUri.Query))
        path = path.Replace(HtmlPage.Document.DocumentUri.Query, "");

      path = path.Replace(HtmlPage.Document.DocumentUri.AbsolutePath, "");
      path = path.Replace(HtmlPage.Document.DocumentUri.Fragment, "");

      return path;
    }

    public static string ObjectToString(People item)
    {
      string outData = string.Empty;

      Type type = item.GetType();
      PropertyInfo[] properties = type.GetProperties();
      foreach (PropertyInfo p in properties)
      {
        if (p.GetValue(item, null) != null)
        {
          outData += String.Format("{0}\t{1}", p.Name, p.GetValue(item, null));
          outData += Environment.NewLine;
        }
      }

      return outData;
    }
  }
}
